<template>
  <div>
    <div style="background-color: #0084ff;border-radius: 150px;width: 300px;margin-bottom: 30px;">
      <h3 style="text-align: center;padding: 10px;color: white">博客数据可视化</h3>
    </div>
    <div style="border: 2px solid #20a4fa;border-radius: 20px;padding: 15px">
      <el-row :gutter="20">
        
        <el-col :span="6">
          <el-statistic :value="watchCount" :title="'🔴浏览量总数'"></el-statistic>
        </el-col>
        
        <el-col :span="6">
          <el-statistic :value="starCount" :title="'🟠点赞量总数'"></el-statistic>
        </el-col>
        
        <el-col :span="6">
          <el-statistic :value="collectionCount" :title="'🟢收藏量总数'"></el-statistic>
        </el-col>
        
        <el-col :span="6">
          <el-statistic :value="commentCount" :title="'🟡评论数量'"></el-statistic>
        </el-col>
      
      </el-row>
    </div>
    <br>
    <br>
    <!--折线图-->
    <div class="line" id="Line">
    </div>
    <!--饼图-->
    <div class="pie" id="Pie">
    </div>
    <div style="clear: both"></div>
    
    <radar-custom/>
    <pie-simple/>
    <br>
  </div>
</template>

<script>
import RadarCustom from "@/pages/DataVisualizationCenter/MyChart/RadarCustom.vue";
import PieSimple from "@/pages/DataVisualizationCenter/MyChart/PieSimple.vue";
import {getBlogCount} from "@/api/dataView/blog";

export default {
  name: "BlogChart",
  data() {
    return {
      watchCount: 0,
      starCount: 0,
      collectionCount: 0,
      commentCount: 0,
    }
  },
  components: {
    RadarCustom,
    PieSimple,
  },
  created() {
    getBlogCount().then((res) => {
      this.watchCount = res.data.data.watchCount
      this.starCount = res.data.data.starCount
      this.collectionCount = res.data.data.collectionCount
      this.commentCount = res.data.data.commentCount
    })
  },
  mounted() {
    // 在通过mounted调用即可
    this.echartsInitPie();
    this.echartsInitLine();
  },
  methods: {
    //初始化饼图
    echartsInitPie() {
      this.$echarts.init(document.getElementById('Pie')).setOption({
        tooltip: {
          trigger: 'item',
        },
        legend: {
          top: '0%',
          left: 'center'
        },
        series: [
          {
            name: '文章类型&数量',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              {value: 3, name: 'Java'},
              {value: 1, name: 'vue'},
              {value: 5, name: 'algorithm'},
              {value: 1, name: 'answer'},
              {value: 4, name: 'essay'},
              {value: 1, name: 'Javascript'},
              {value: 1, name: 'css'},
              {value: 1, name: 'Python'},
            ]
          }
        ]
      })
    },
    // 初始化折线图
    echartsInitLine() {
      this.$echarts.init(document.getElementById('Line')).setOption({
        title: {
          text: '观看人数'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['Java', '算法', '随笔', 'JavaScript', 'Python']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['2月', '3月', '4月', '5月', '6月', '7月', '8月']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: 'Java',
            type: 'line',
            stack: 'Total',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '算法',
            type: 'line',
            stack: 'Total',
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '随笔',
            type: 'line',
            stack: 'Total',
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: 'JavaScript',
            type: 'line',
            stack: 'Total',
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: 'Python',
            type: 'line',
            stack: 'Total',
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      })
    }
  }
}
</script>

<style scoped>
.like {
  cursor: pointer;
  font-size: 25px;
  display: inline-block;
}

.line {
  width: 700px;
  height: 400px;
  float: right;
  margin-right: 30px;
}

.pie {
  margin-bottom: 50px;
  width: 400px;
  height: 400px;
  float: left;
}
</style>
